import useStore from '@/stores'
import { getDictListByDictType } from '@/api/power/dict'
import { type DictData } from '@/api/power/dict'

export function useDict(...args: string[]) {
  const dictMap = ref<Record<string, DictData[]>>({})
  const { dict } = useStore()
  args.forEach((key: string) => {
    dictMap.value[key] = []
    const dictData = dict.getDict(key)
    if (dictData) {
      dictMap.value[key] = dictData
    } else {
      getDictListByDictType(key).then(res => {
        dict.setDict(key, res.data)
        dictMap.value[key] = res.data
      })
    }
  })
  return toRefs(dictMap.value)
}
